home *** CD-ROM | disk | FTP | other *** search
/ Your Choice 3 / Your Choice Software Collection 3.iso / os2 / grfcdemo / demo.@ / SAMPLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  3.0 KB  |  74 lines

  1. /****************************************************************************
  2.     (c) 1984-1993 by Scientific Endeavors Corporation.
  3.     All rights reserved.
  4.  
  5.     This program plots a single curve on a set of 2-D linear axes. Except for
  6.     color(), sympick(), and grid(), this simple example program uses only
  7.     the minimum calls needed to produce a GraphiC plot.
  8. ****************************************************************************/
  9.  
  10. #include <graphic.h>                           /* Include all needed files */
  11.  
  12. #if TCQ                                 /* Set stack for Borland (Turbo) C */
  13. extern unsigned _stklen = 0x3000;
  14. #endif
  15.  
  16. /****************************************************************************
  17.     Main program
  18. ****************************************************************************/
  19. #ifdef ANSI
  20. void GPC_MAIN(void)
  21. #else
  22. void GPC_MAIN()
  23. #endif
  24. {
  25.     G_PFQ(x, hx);
  26.     G_PFQ(y, hy);
  27.     int i, nxdiv, nydiv, npts;
  28.  
  29.     npts = 301;                   /* Is the # of points in x and y vectors */ 
  30.     x = (float DIST *)GPC_ALLOC(&hx, npts, sizeof(float));
  31.     y = (float DIST *)GPC_ALLOC(&hy, npts, sizeof(float));
  32.     if(x == (float DIST *)NULL || y == (float DIST *)NULL) {
  33.         GPC_PUTS("SAMPLE: Could not allocate data arrays");
  34.         goto EndOfApp;
  35.     }
  36.  
  37.     bgnplot(1, 'g', "sample.tkf");    /* Parameters: 1 -- draw plot on screen
  38.                                                    'g' -- graphics mode
  39.                                           "sample.tkf" -- .TKF file name   */
  40.     startplot(WHITE);
  41.     metricunits(0);                        /* Ensure scaling in inch units */
  42.     font(1, "simplex.fnt", '\310');              /* Loads your chosen font */
  43.  
  44.     page(9.0f, 6.884f);                              /* Sets the page size */
  45.                           /* This is the same aspect ratio as 4095 by 3132 */
  46.     area2d(7.6f, 5.5f);                       /* Sets the area of the plot */
  47.  
  48.     for(i = 0; i < npts; i++){                            /* Generate data */
  49.         y[i] = .3f * i;
  50.         x[i] = (y[i] * y[i]) / 2.f;
  51.     }
  52.     color(BLACK);                  /* Axis names and heading will be black */
  53.     xname("\310X-Axis");
  54.     yname("Y-Axis");
  55.     heading("SAMPLE PLOT");
  56.     grid(9);               /* Draws grid through tick marks, 9 -- fine dot */
  57.     nxdiv = 5;                   /* Sets the desired # of x-axis divisions */
  58.     nydiv = 6;                   /* Sets the desired # of y-axis divisions */
  59.     color(GREEN);                                 /* Green axes and labels */
  60.     scales(nxdiv, nydiv, x, y, npts);         /* Draws and scales the axes */
  61.  
  62.     color(RED);                                               /* Red curve */
  63.     sympick(12);                                  /* Filled circle symbols */
  64.     curve(x, y, npts, 10);
  65.  
  66.     endplot();         /* Finishes plot and waits for instructions to exit or
  67.                         draw next plot.  Resets file pointers and defaults */
  68.     stopplot();          /* Close files, return to text mode, exit program */
  69.  
  70. EndOfApp:
  71.     GPC_FREE(&hx, &x);
  72.     GPC_FREE(&hy, &y);
  73. }
  74.